package com.gesis.utils;

import java.io.File;
import java.util.List;

import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

import com.gesis.entity.GesTopic;
import com.gesis.properties.LoaderResourceElements;

public class ExportXLS {

	private String nameFile;
	private String nameBook;
	private String nameSheet;
	private String title1;
	private String title2;
	private String dirName;

	public String generateXLSDate(List<GesTopic> lstTopic) {

		File exportFile = null;
		try {
			nameBook = "ProjectBook";
			nameFile = "Project";
			nameSheet = "Date";

			JExcel jbe = new JExcel();
			dirName = LoaderResourceElements.getInstance().getParameters("destino.export");
			exportFile = new File(dirName + nameFile + ".xls");
			
			WritableWorkbook libro = jbe.crearLibro(exportFile);
			WritableSheet hoja = jbe.crearHoja(nameSheet, 0, libro);
			
			jbe.ingresarTexto(0, 0, LoaderResourceElements.getInstance()
					.getLabels("ges_project"), hoja, 3);
			jbe.ingresarTexto(1, 0, LoaderResourceElements.getInstance()
					.getLabels("ges_collaborator1"), hoja, 3);
			jbe.ingresarTexto(2, 0, LoaderResourceElements.getInstance()
					.getLabels("ges_collaborator2"), hoja, 3);
			jbe.ingresarTexto(3, 0, LoaderResourceElements.getInstance()
					.getLabels("ges_collaborator3"), hoja, 3);
			jbe.ingresarTexto(4, 0, LoaderResourceElements.getInstance()
					.getLabels("ges_collaborator4"), hoja, 3);
			jbe.ingresarTexto(5, 0, LoaderResourceElements.getInstance()
					.getLabels("ges_collaborator5"), hoja, 3);
			jbe.ingresarTexto(6, 0, LoaderResourceElements.getInstance()
					.getLabels("ges_collaborator6"), hoja, 3);
			jbe.ingresarTexto(7, 0, LoaderResourceElements.getInstance()
					.getLabels("ges_collaborator7"), hoja, 3);
			jbe.ingresarTexto(8, 0, LoaderResourceElements.getInstance()
					.getLabels("ges_collaborator8"), hoja, 3);
			jbe.ingresarTexto(9, 0, LoaderResourceElements.getInstance()
					.getLabels("ges_collaborator9"), hoja, 3);
			jbe.ingresarTexto(10, 0, LoaderResourceElements.getInstance()
					.getLabels("ges_collaborator10"), hoja, 3);
			jbe.ingresarTexto(11, 0, LoaderResourceElements.getInstance()
					.getLabels("ges_collaborator11"), hoja, 3);
			jbe.ingresarTexto(12, 0, LoaderResourceElements.getInstance()
					.getLabels("ges_collaborator12"), hoja, 3);
			jbe.ingresarTexto(13, 0, LoaderResourceElements.getInstance()
					.getLabels("ges_collaborator13"), hoja, 3);
			jbe.ingresarTexto(14, 0, LoaderResourceElements.getInstance()
					.getLabels("ges_collaborator14"), hoja, 3);
			jbe.ingresarTexto(15, 0, LoaderResourceElements.getInstance()
					.getLabels("ges_collaborator15"), hoja, 3);
			jbe.ingresarTexto(16, 0, LoaderResourceElements.getInstance()
					.getLabels("ges_collaborator16"), hoja, 3);
			jbe.ingresarTexto(17, 0, LoaderResourceElements.getInstance()
					.getLabels("ges_collaborator17"), hoja, 3);
			jbe.ingresarTexto(18, 0, LoaderResourceElements.getInstance()
					.getLabels("ges_collaborator18"), hoja, 3);
			jbe.ingresarTexto(19, 0, LoaderResourceElements.getInstance()
					.getLabels("ges_collaborator19"), hoja, 3);
			jbe.ingresarTexto(20, 0, LoaderResourceElements.getInstance()
					.getLabels("ges_collaborator20"), hoja, 3);
			jbe.ingresarTexto(21, 0, LoaderResourceElements.getInstance()
					.getLabels("ges_collaborator21"), hoja, 3);
			jbe.ingresarTexto(22, 0, LoaderResourceElements.getInstance()
					.getLabels("ges_collaborator22"), hoja, 3);
			jbe.ingresarTexto(23, 0, LoaderResourceElements.getInstance()
					.getLabels("ges_collaborator23"), hoja, 3);
			
			int i = 1;
			for (GesTopic gesTopic : lstTopic) {
				jbe.ingresarTexto(0, i, gesTopic.getTopNameTopic(), hoja, 0);
				jbe.ingresarTexto(1, i, gesTopic.getTopP1(), hoja, 0);
				jbe.ingresarTexto(2, i, gesTopic.getTopP2(), hoja, 0);
				jbe.ingresarTexto(3, i, gesTopic.getTopP3(), hoja, 0);
				jbe.ingresarTexto(4, i, gesTopic.getTopP4(), hoja, 0);
				jbe.ingresarTexto(5, i, gesTopic.getTopP5(), hoja, 0);
				jbe.ingresarTexto(6, i, gesTopic.getTopP6(), hoja, 0);
				jbe.ingresarTexto(7, i, gesTopic.getTopP7(), hoja, 0);
				jbe.ingresarTexto(8, i, gesTopic.getTopP8(), hoja, 0);
				jbe.ingresarTexto(9, i, gesTopic.getTopP9(), hoja, 0);
				jbe.ingresarTexto(10, i, gesTopic.getTopP10(), hoja, 0);
				jbe.ingresarTexto(11, i, gesTopic.getTopP11(), hoja, 0);
				jbe.ingresarTexto(12, i, gesTopic.getTopP12(), hoja, 0);
				jbe.ingresarTexto(13, i, gesTopic.getTopP13(), hoja, 0);
				jbe.ingresarTexto(14, i, gesTopic.getTopP14(), hoja, 0);
				jbe.ingresarTexto(15, i, gesTopic.getTopP15(), hoja, 0);
				jbe.ingresarTexto(16, i, gesTopic.getTopP16(), hoja, 0);
				jbe.ingresarTexto(17, i, gesTopic.getTopP17(), hoja, 0);
				jbe.ingresarTexto(18, i, gesTopic.getTopP18(), hoja, 0);
				jbe.ingresarTexto(19, i, gesTopic.getTopP19(), hoja, 0);
				jbe.ingresarTexto(20, i, gesTopic.getTopP20(), hoja, 0);
				jbe.ingresarTexto(21, i, gesTopic.getTopP21(), hoja, 0);
				jbe.ingresarTexto(22, i, gesTopic.getTopP22(), hoja, 0);
				jbe.ingresarTexto(23, i, gesTopic.getTopP23(), hoja, 0);
				i++;
			}
			jbe.ejecutar(libro);
		} catch (Exception e) {
			e.printStackTrace();
			}
		return exportFile.getAbsolutePath();
	}

	public String getNameFile() {
		return nameFile;
	}

	public void setNameFile(String nameFile) {
		this.nameFile = nameFile;
	}

	public String getNameBook() {
		return nameBook;
	}

	public void setNameBook(String nameBook) {
		this.nameBook = nameBook;
	}

	public String getNameSheet() {
		return nameSheet;
	}

	public void setNameSheet(String nameSheet) {
		this.nameSheet = nameSheet;
	}

	public String getTitle1() {
		return title1;
	}

	public void setTitle1(String title1) {
		this.title1 = title1;
	}

	public String getTitle2() {
		return title2;
	}

	public void setTitle2(String title2) {
		this.title2 = title2;
	}

	public String getDirName() {
		return dirName;
	}

	public void setDirName(String dirName) {
		this.dirName = dirName;
	}
}
